W5. Regular Limits and Stacks
1. Theory
1.1 Why Some Languages Are Not Regular
Recall that a regular language is any language that can be recognized by a finite state automaton (FSA). FSAs are powerful tools, but they have a fundamental limitation: they have only a fixed, finite amount of memory—precisely the current state. An FSA with
This limitation means FSAs cannot handle patterns that require counting to an arbitrary depth. For example:
: To recognize this, the machine must count a’s and then verify exactly b’s. No matter how many states the FSA has, a sufficiently large will overflow its memory. : Even-length palindromes. To recognize these, the machine must remember the entire first half of the string, which can be arbitrarily long.
To prove that a language is regular, we just exhibit a working FSA. To prove that a language is not regular, however, we face a harder task: we must show that no possible FSA can recognize it. Checking every finite automaton is clearly impossible. Instead, we use a powerful theoretical tool: the Pumping Lemma.
1.2 The Pigeonhole Principle
Before stating the Pumping Lemma, we need the classic Pigeonhole Principle:
If
pigeons are placed into pigeonholes and , then at least one pigeonhole must contain at least two pigeons.
Application to FSAs: Think of the states of an FSA as pigeonholes and the transitions traversed while reading a string as pigeons. If a string has length greater than the number of states
1.3 Infinite Regular Languages Must Have Cycles
Consider an infinite regular language
This means the automaton’s path looks like:
1.4 The Pumping Lemma for Regular Languages
1.4.1 Formal Statement
Pumping Lemma: If
(the “pump” is non-empty) (the pump occurs early in the string) for all (pumping any number of times stays in )
The pumping length
Proof sketch: Let
Since the first repetition must occur within the first
1.4.2 Necessary but Not Sufficient
The Pumping Lemma gives only a necessary condition for regularity, not a sufficient one. This means:
- If
is regular satisfies the Pumping Lemma (guaranteed) - If
satisfies the Pumping Lemma is regular (some non-regular languages also satisfy it!)
Therefore:
- Cannot use it to prove a language is regular
- Can use it to prove a language is not regular (via the contrapositive)
1.4.3 The Contrapositive: Proving Non-Regularity
The contrapositive of the Pumping Lemma is:
If for every integer
there exists a string with such that for every decomposition with and , there exists some with , then is not regular.
This is the tool we actually use. Think of it as a two-player game:
| Player 1 (Adversary) | Player 2 (You) |
|---|---|
| Picks any |
You choose |
| Picks any split |
You find |
You win (language is not regular) if you can always respond successfully, regardless of the adversary’s choices.
1.4.4 Standard Proof Template
Here is the standard structure for a Pumping Lemma proof:
- Assume for contradiction that
is regular. - Let
be the pumping length given by the Pumping Lemma. - Choose a specific word
with (pick it cleverly so that any valid split must pump outside ). - Consider an arbitrary valid split
with and . - Use the constraint
to restrict where can appear. - Find a specific
such that . - Conclude that the Pumping Lemma is violated, so
is not regular.
Choosing the right word is the most creative step. A good choice forces
1.4.5 Classic Example:
Claim:
Proof:
- Suppose
is regular. Let be the pumping length. - Choose
. Note . - Consider any split
with and . - Since
and the first characters of are all ’s, the substring lies entirely within the -block. Therefore and for some , with . - So
. - Consider
: . - Since
, the pumped string has a’s and only b’s. Therefore .
This contradicts the Pumping Lemma. Therefore
Three cases of the lecture analysis: The lecture also directly analyzed all possible splits without relying on
- Case 1:
(only a’s) — pumping gives (more a’s than b’s) - Case 2:
(only b’s) — pumping gives (more b’s than a’s) - Case 3:
(mixed) — pumping gives (b’s appear in the middle)
In all cases, some pumped string is not of the form
1.5 Pushdown Automata
1.5.1 Motivation: Going Beyond Regular Languages
The Pumping Lemma shows that FSAs are insufficient for languages like
The hierarchy of computational models (from weakest to strongest) looks like:
- Combinational logic (no memory, just Boolean circuits)
- Finite State Automata (fixed, finite memory: only the current state)
- Pushdown Automata (unbounded stack memory: can recognize context-free languages)
- Turing Machines (unlimited tape memory: can compute anything computable)
PDAs sit precisely in the layer above FSAs and are capable of recognizing context-free languages (CFLs), which include most programming language constructs (nested brackets, balanced parentheses, etc.).
1.5.2 What is a Stack?
A stack is a last-in, first-out (LIFO) data structure. Think of a stack of plates: you can only add or remove from the top.
Operations:
- Push: Insert a new symbol on top of the stack.
- Pop: Remove the top symbol from the stack (also “reading” it).
The stack always has a special bottom-of-stack symbol
Example — push
Starting from an empty stack (containing only
- After pushing
: stack (top to bottom) - After pushing
: stack - After pushing
: stack - After popping:
is removed; stack
The last symbol pushed (
Historical note: The concept of a stack was introduced by Alan Turing in his 1946 paper on the Automatic Computing Engine (ACE). He called the operations BURY and UNBURY, and used them in the theory of subroutines.
1.5.3 Informal Description
An FSA has a read head on an input tape and a finite control unit that remembers the current state.
A Pushdown Automaton is identical, but adds a stack as external memory:
- The finite control reads the next input symbol and the top of the stack.
- Based on these (and the current state), it transitions to a new state and replaces the top of the stack with a string of symbols.
The PDA can:
- Push symbols onto the stack (by replacing the top with a longer string)
- Pop the top symbol (by replacing it with
) - Leave the stack unchanged (by replacing the top with itself)
- Make
-moves (read nothing from input, only modify the stack)
1.5.4 Formal Definition
A Pushdown Automaton is a 7-tuple:
where:
: finite set of states : finite input alphabet : finite stack alphabet (symbols that can appear on the stack) : the transition function : the initial state : the initial stack symbol (bottom-of-stack marker) : the set of accepting (final) states
Reading the transition function: A transition
Transitions are written on arrows as:
- To push
below : write (replace with ; is now on top) - To pop
: write (replace with nothing) - To leave stack unchanged: write
1.5.5 Moves of a PDA
Each step of a PDA depends on three things:
- The current state
- The current input symbol (or
for a silent move) - The top of the stack
In one move, the PDA simultaneously:
- Changes state to some
- Advances the input head (or stays put for
-moves) - Replaces the top-of-stack symbol
with a string
Since
1.5.6 Acceptance Conditions
A PDA can accept input in two different ways:
- Acceptance by final state: The input is fully consumed and the PDA is in an accepting state
. The stack content does not matter. - Acceptance by empty stack: The input is fully consumed and the stack is empty (contains only
or nothing). The state does not matter.
For nondeterministic PDAs, these two acceptance modes are equivalent: any language accepted by one mode can be accepted by the other with an appropriate PDA. For deterministic PDAs, however, the two modes are not equivalent.
Note: Acceptance by empty stack has a subtle restriction: the language accepted by an empty-stack PDA must be prefix-free (no string in the language is a proper prefix of another string in the language). This is because once the stack empties on reading
1.5.7 Step-by-Step Example: PDA for
The key idea: push one
PDA construction:
States:
Stack alphabet:
Transitions:
: — read first ; push on top of : — read subsequent ’s; push another : — first ; pop one : — subsequent ’s; pop one each time : — end of input; if is on top (all ’s were popped), accept
Trace for input “aabb”:
| Step | State | Remaining Input | Stack (top first) | Transition |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ACCEPT |
2. Definitions
- Regular Language: A language
that can be recognized by some finite state automaton. Equivalently, a language for which there exists an FSA with . - Pumping Lemma: A theorem stating that every regular language
has a pumping length such that any word with can be split as with , , and for all . - Pumping Length (
): The critical length in the Pumping Lemma; can be taken as the number of states in the FSA recognizing the language. Any string in the language of length must be “pumpable.” - Pumping (of a string): Repeating the middle portion
of a decomposition any number of times. Pumping times gives . - Contrapositive of the Pumping Lemma: If for every
there exists with such that every valid split (with , ) has some with , then is not regular. - Pigeonhole Principle: If
objects are placed into containers, at least one container must hold more than one object. - Cycle (in an FSA): A path in the state diagram that starts and ends at the same state. In infinite regular languages, cycles are necessary for generating infinitely many strings.
- Pushdown Automaton (PDA): A computational model consisting of a finite control unit, an input tape, and a stack. Formally a 7-tuple
. PDAs recognize exactly the class of context-free languages. - Stack: A last-in, first-out (LIFO) data structure used by a PDA as its memory. Supports two operations: push (add to top) and pop (remove from top).
- Stack Alphabet (
): The finite set of symbols that may appear on the PDA’s stack. Typically includes a special bottom-of-stack marker . - Bottom-of-Stack Symbol (
): A special symbol at the bottom of the PDA’s stack, used to detect when the stack is empty. - PDA Transition Function (
): A function specifying the PDA’s moves. A transition means: in state , reading from input and from the stack top, move to state and replace with string . -move: A transition in a PDA that reads no input symbol. The PDA changes state and modifies the stack without consuming any input character.- Acceptance by Final State: A PDA accepts a string if, after consuming all input, it is in a state
. - Acceptance by Empty Stack: A PDA accepts a string if, after consuming all input, the stack is empty (contains only
). Equivalent to acceptance by final state for nondeterministic PDAs. - Context-Free Language (CFL): A language recognized by a pushdown automaton, or equivalently, generated by a context-free grammar. Every regular language is context-free, but not vice versa.
- Nondeterministic PDA: A PDA where
may contain multiple possible transitions (a set of size ). The PDA accepts if some sequence of choices leads to acceptance. - Deterministic PDA (DPDA): A PDA with at most one possible transition at each step:
for all , and implies .
3. Formulas
- Pumping Lemma (Regular Languages): For regular
, such that with , split with , , and - Contrapositive (for proofs):
is not regular if , with such that splits with and , - Length after pumping:
- Constraint on split location:
forces to lie within the first symbols of - PDA transition notation:
— read from input, pop from stack, push ; write for a silent ( -)move - PDA formal definition:
where - Acceptance by final state:
is accepted iff for some and
4. Practice
4.1. Prove is Not Regular (Lab 5, Task 1)
Use the Pumping Lemma to prove that
(Note:
Click to see the solution
Key Concept: Note that
- Assume for contradiction that
is regular. Let be the pumping length. - Choose the word
(take , so and ). Note . - Consider an arbitrary split
with and . - Restrict
: The first characters of are all ’s, and , so lies in the -prefix. Thus , with , , and . - Pump with
(remove one copy of ): - Verify failure: The string
has leading ’s and trailing ’s. For it to be in (an even-length palindrome), the -th character from the left must equal the -th character from the right.- The
-th character from the left: the first characters are ’s, so position is the first . Character = . - The
-th character from the right: the last characters are ’s. Since (as ), position from the right is still in the trailing -block. Character = . - Since
, the string is not a palindrome, so .
- The
- Conclusion: The Pumping Lemma is violated. Therefore
is not regular.
Answer:
4.2. Prove is Not Regular (Lab 5, Task 2)
Use the Pumping Lemma to prove that
Click to see the solution
Key Concept: Any string in
- Assume for contradiction that
is regular. Let be the pumping length. - Choose the word
( ’s and ’s). Note . - Consider an arbitrary split
with and . - Restrict
: Since the first characters are ’s and , lies in the -block. So with and . - Pump with
: - Verify failure:
and . Since , , so the counts are unequal. Therefore . - Conclusion: The Pumping Lemma is violated. Therefore
is not regular.
Answer:
4.3. Prove is Not Regular (Lab 5, Task 3)
Use the Pumping Lemma to prove that
(Note:
Click to see the solution
Key Concept: Factorials grow faster than any linear function. Consecutive factorials satisfy
- Assume for contradiction that
is regular. Let be the pumping length. - Choose the word
. Note for . - Consider an arbitrary split
with and . - Determine
: Let . Since , we have . - Pump with
: - Verify failure:
- Lower bound:
(since ). - Upper bound:
. - Gap to next factorial:
. We need , i.e., , i.e., . Since for , this holds. - Therefore
, so is strictly between two consecutive factorials and equals no factorial. - Hence
.
: the only split has . We use : . Since for any (as always), . ) - Lower bound:
- Conclusion: In all cases, some pumped word is not in
. The Pumping Lemma is violated. Therefore is not regular.
Answer:
4.4. Prove is Not Regular (Lab 5, Task 4)
Use the Pumping Lemma to prove that
Click to see the solution
Key Concept: In
- Assume for contradiction that
is regular. Let be the pumping length. - Choose the word
(take , so ). Note . - Consider an arbitrary split
with and . - Restrict
: The first characters of are all ’s, so forces to lie entirely in the -block. Thus with , and . - Pump with
: - Verify failure: For
, we’d need a’s, b’s, and the number of ’s to equal . But the actual number of ’s is (since ). Therefore . - Conclusion: The Pumping Lemma is violated. Therefore
is not regular.
Answer:
4.5. Prove is Not Regular (Tutorial 5, Example 1)
Use the Pumping Lemma to prove that
Click to see the solution
Key Concept: Choose the word
- Assume for contradiction that
is regular. Let be the pumping length. - Choose the word
. Note , so the Pumping Lemma applies. - Consider an arbitrary split
with and . - Restrict the position of
: Since the first characters of are all ’s, and , the portion consists entirely of ’s. Therefore and for some , with , and . - Pump with
: - Verify failure: Since
, we have , so (unequal counts of ’s and ’s). - Conclusion: The Pumping Lemma is violated. Therefore
is not regular.
Additional analysis — all three split cases: The lecture also showed this by exhausting all possible placements of
- (a)
: pumping gives . - (b)
: pumping gives . - (c)
( ): pumping gives . The middle contains ’s followed by ’s, so this string is not of the form . Thus not in .
In all three cases, pumping fails.
Answer:
4.6. Prove is Not Regular (Tutorial 5, Example 2)
Use the Pumping Lemma to prove that
Click to see the solution
Key Concept: Choose
Assume for contradiction that
is regular. Let be the pumping length.Choose the word
. Note .Consider an arbitrary split
with and .Restrict
: Since and the first characters are all ’s, lies entirely in the leading -block. So (for some decomposition), with , .More precisely:
, , with , .Pump with
:Verify failure:
. For this to be in , we’d need , but means . The left and right -blocks have different lengths, so .Conclusion: Pumping Lemma is violated.
is not regular.
Answer:
4.7. Construct a PDA for (Tutorial 5, Example 3)
Show that
Click to see the solution
Key Concept: Use the stack to count
Design the PDA:
- States:
(start), (reading ’s), (reading ’s), (accepting) - Stack alphabet:
- States:
Transitions:
Transition Meaning :First : push onto the stack :Each additional : push :First : pop one :Each additional : pop one :End of input with on top: acceptTrace for
: : stack = : stack = : stack = : stack = : ACCEPT
Correctness:
- On input
: exactly ’s are pushed, then ’s are popped. The stack returns to , and the PDA accepts. - On input
with : either ’s remain on the stack when ’s run out, or is encountered before all ’s are read. Neither reaches on a valid -transition.
- On input
Answer: The PDA with states
4.8. Construct a PDA for (Tutorial 5, Example 4)
Show that
Click to see the solution
Key Concept: Push one
Design the PDA:
- States:
(start, reading left ’s), (pivot: saw , now reading right ’s), (accepting) - Stack alphabet:
- States:
Transitions:
Transition Meaning :First (left side): push :Each additional (left side): push :See the : do not pop yet, transition to reading right ’s :Each on the right side: pop one :All ’s matched; on top: acceptTrace for
: : stack = : stack = (stack unchanged, state changes) : stack = : ACCEPT
Trace for
: : stack = : stack = : stack = : stack = : stack = : ACCEPT
Answer: The PDA with states